import { Controller } from "../../mvc/core/Controller";
import { ThingUtil } from "../scene/layer/utils/ThingUtil";
import { SEntityId } from "../../../Message/Public/SEntityId";
import { SEntityMoveInfo } from "../../../Message/BroadCast/SEntityMoveInfo";
import { AStarPoint } from "../scene/map/AStarPoint";
import { SEntityUpdate } from "../../../Message/BroadCast/SEntityUpdate";
import { EntityUtil } from "../scene/layer/utils/EntityUtil";
import { SPacket } from "../../../Message/Public/SPacket";
import { SNpcShop } from "../../../Message/Public/SNpcShop";
import { IView } from "../../mvc/interfaces/IView";
import { Game } from "../Game";
import { SceneEvent } from "../scene/events/SceneEvent";
import { Dispatcher } from "../../mvc/core/Dispatcher";
import { EventName } from "../mvc/EventName";
import { DataEvent } from "../events/DataEvent";
import { SkillUseLaterUtil } from "../scene/skill/useLater/SkillUseLaterUtil";
import { IEntity } from "../scene/player/IEntity";
import { Log } from "../../../com/gengine/debug/Log";
import { SDropItem } from "../../../Message/Public/SDropItem";
import { AIManager } from "../scene/ai/AIManager";
import { RolePlayer } from "../scene/player/entity/RolePlayer";
import { PlayerEvent } from "../scene/events/PlayerEvent";
import { MouseFollow } from "../scene/mouse/MouseFollow";
import { Cache } from "../cache/Cache";
import { MapDataUpdater } from "../scene/map/MapDataUpdater";
import { NetDispatcher } from "../../mvc/core/NetDispatcher";
import { ServerCommand } from "../mvc/ServerCommand";
import { Global } from "../../../com/gengine/global/Global";
import { ScreenOperation } from "../scene/ScreenOperation";
import { GameController } from "../mvc/GameController";
import { GameMapUtil } from "../scene/map/GameMapUtil";
import { GameProxy } from "../mvc/GameProxy";
import { EatBeansDoingStatus } from "../view/copy/eatBeans/EatBeansDoingStatus";
import { MsgManager } from "../manager/MsgManager";
import { Language } from "../../../extend/language/Language";
import { UserPlayer } from "../scene/player/entity/UserPlayer";
import { MonsterPlayer } from "../scene/player/entity/MonsterPlayer";
import { BossRule } from "../rules/BossRule";
import { NPCPlayer } from "../scene/player/entity/NPCPlayer";
import { SoundManager } from "../../common/sound/SoundManager";
import { SoundTypeConst } from "../../common/sound/SoundTypeConst";
import { GameSprite } from "../../../com/gengine/game/core/GameSprite";
import { SystemSetter } from "../view/system/SystemSetter";
import { AIType } from "../scene/ai/AIType";
import { AutoFightRule } from "../rules/AutoFightRule";
import { SBeginFight } from "../../../Message/BroadCast/SBeginFight";
import { SpritePlayer } from "../scene/player/entity/SpritePlayer";
import { EEntityAttribute } from "../../../Message/Public/EEntityAttribute";
import { SkillConfig } from "../resource/SkillConfig";
import { ESkillType } from "../../../Message/Public/ESkillType";
import { ECmdBroadCast } from "../../../Message/Command/ECmdBroadCast";
import { EPublicCommand } from "../../../Message/Command/EPublicCommand";
import { EGateCommand } from "../../../Message/Command/EGateCommand";
import { RolePlayerEvent } from "../scene/events/RolePlayerEvent";
import { ClockManager } from "../manager/ClockManager";
import { TimeEvent } from "../events/TimeEvent";
import { ActiveShieldConfig } from "../resource/ActiveShieldConfig";
import { SceneConfig } from "../resource/SceneConfig";
import { CopyCodeRule } from "../rules/CopyCodeRule";
import { SPassPoint } from "../../../Message/Public/SPassPoint";
import { EatParadeConfig } from "../resource/EatParadeConfig";
import { AttributeValue } from "../scene/player/AttributeValue";
import { MessageBlock } from "../../../Framework/MQ/MessageBlock";
import { SPoints } from "../../../Message/Public/SPoints";
import { SkillProgress } from "../view/common/SkillProgress";
import { ProcessType } from "../rules/ProcessType";
import { SPassTo } from "../../../Message/Public/SPassTo";
import { MapFileUtil } from "../scene/map/MapFileUtil";
import { MapLoader } from "../scene/map/MapLoader";
import { SceneRange } from "../scene/map/SceneRange";
import { MouseRuleManager } from "../scene/mouse/MouseRuleManager";
import { MouseThreeClickRule } from "../scene/mouse/MouseThreeClickRule";
import { SBuffer } from "../../../Message/Public/SBuffer";
import { SNpcTalk } from "../../../Message/Public/SNpcTalk";
import { ItemConfig } from "../resource/ItemConfig";
import { SMapPassPointList } from "../../../Message/Public/SMapPassPointList";
import { SArenaCrossStatues } from "../../../Message/Public/SArenaCrossStatues";
import { SCrossFlowerToplistStatues } from "../../../Message/Public/SCrossFlowerToplistStatues";
import { SkillInfo } from "../model/SkillInfo";
import { SkillsUtil } from "../scene/skill/SkillsUtil";
import { ItemData } from "../resource/info/ItemData";
import { MountUtil } from "../scene/mount/MountUtil";
import { SEntityIdPair } from "../../../Message/Public/SEntityIdPair";
import { NpcShopInfo } from "../scene/player/info/NpcShopInfo";
import { SEntityInfo } from "../../../Message/BroadCast/SEntityInfo";
import { SSeqEntityInfo } from "../../../Message/BroadCast/SSeqEntityInfo";
import { SSeqEntityIdInfo } from "../../../Message/BroadCast/SSeqEntityIdInfo";
import { FrameUtil } from "../../../com/gengine/core/FrameUtil";
import { SShortcut } from "../../../Message/Game/SShortcut";
import { SDoFight } from "../../../Message/BroadCast/SDoFight";
import { SDoFights } from "../../../Message/BroadCast/SDoFights";
import { GameScene } from "../scene/GameScene";
type int = number;
//class SceneController
    
    export  class SceneController extends Controller
    {
        constructor()
        {
            
            super();this._entritysAry = [];
            this._dropItemAry = [];
            this._simpleDropItem = [];
            this._npcShopAry = [];
            return;
        }

        public removeEntitys(arg1: Array<any>): void
        {
            if (this._scene) 
            {
                ThingUtil.entityUtil.removeEntitys(arg1);
            }
            return;
        }

        public removeEntity(arg1: SEntityId): void
        {
            if (this._scene) 
            {
                ThingUtil.entityUtil.removeEntity(arg1);
            }
            return;
        }

        public moveEntity(arg1: SEntityMoveInfo, arg2: Array<any>): void
        {
            var loc1=null;
            var loc2=null;
            var loc3=0;
            var loc4=null;
            if (this._scene) 
            {
                loc1 = [];
                loc3 = 0;
                while (loc3 < arg2.length) 
                {
                    loc2 = arg2[loc3];
                    loc4 = new AStarPoint(loc2.x, loc2.y);
                    loc1.push(loc4);
                    ++loc3;
                }
                ThingUtil.entityUtil.moveEntity(arg1, loc1);
            }
            return;
        }

        /* internal  */updateAttributes(arg1: SEntityUpdate): void
        {
            var loc1=null;
            if (this._scene && this._scene.isInitialize) 
            {
                ThingUtil.userUtil.updateAttribute(arg1);
            }
            else 
            {
                var loc2=0;
                var loc3=this._entritysAry;
                for(loc1 of loc3) 
                {
                    if (EntityUtil.toString(loc1.entityId) != EntityUtil.toString(arg1.entityId)) 
                    {
                        continue;
                    }
                    EntityUtil.updateEntityAttribute(loc1, arg1.propertyUpdates);
                    return;
                }
            }
            return;
        }

        public dropItem(arg1: SPacket): void
        {
            if (this._scene && this._scene.isInitialize) 
            {
                ThingUtil.dropItemUtil.addDropItem(arg1);
            }
            else 
            {
                this._dropItemAry.push(arg1);
            }
            return;
        }

        public entityNpcShop(arg1: SNpcShop): void
        {
            if (this._scene && this._scene.isInitialize) 
            {
                ThingUtil.npcShopUtil.addNpcShop(arg1);
            }
            else 
            {
                this._npcShopAry.push(arg1);
            }
            return;
        }

        protected /* override */ initView(): IView
        {
            this._scene = Game.scene;
            if (this._scene != null) 
            {
                this._scene.addEventListener(SceneEvent.INIT, this.onSceneInitHandler);
                Dispatcher.addEventListener(EventName.Player_Selected, this.onPlayerSelectedHandler, false, 9999);
            }
            return this._scene;
        }

        /* internal  */onPlayerSelectedHandler(arg1: DataEvent): void
        {
            SkillUseLaterUtil.clearSkillUseLater();
            var loc1=arg1.data as IEntity;
            if (loc1 && loc1.selected) 
            {
                if (ThingUtil.selectEntity) 
                {
                    ThingUtil.selectEntity.selected = false;
                }
                ThingUtil.selectEntity = loc1;
            }
            else 
            {
                ThingUtil.selectEntity = null;
            }
            return;
        }

        /* internal  */onNpcSelectedHandler(arg1: DataEvent): void
        {
            Dispatcher.dispatchEvent(arg1);
            return;
        }

        /* internal  */onSceneInitHandler(arg1: SceneEvent): void
        {
            var loc1=null;
            Log.debug("SceneInit:");
            if (this._entritysAry.length) 
            {
                Log.debug("_entritysAry:" + this._entritysAry);
                ThingUtil.entityUtil.addEntitys(this._entritysAry);
                this._entritysAry.length = 0;
            }
            while (this._dropItemAry.length > 0) 
            {
                ThingUtil.dropItemUtil.addDropItem(this._dropItemAry.shift() as SPacket);
            }
            while (this._simpleDropItem.length > 0) 
            {
                ThingUtil.dropItemUtil.addSimpleDropItem(this._simpleDropItem.shift() as SDropItem);
            }
            while (this._npcShopAry.length > 0) 
            {
                ThingUtil.npcShopUtil.addNpcShop(this._npcShopAry.shift() as SNpcShop);
            }
            ThingUtil.passUtil.initPassList();
            if (this._serverOpenDayChange) 
            {
                this.onServerOpenDayChangeHandler(null);
            }
            AIManager.init(this._scene, RolePlayer.instance);
            RolePlayer.instance.addEventListener(PlayerEvent.UPDATEINFO, this.onEntityInfoUpdateHandler);
            RolePlayer.instance.addEventListener(PlayerEvent.GIRD_WALK_START, this.onGirdWalkStartHandler);
            RolePlayer.instance.addEventListener(PlayerEvent.ServerPoint, this.onGirdWalkStartHandler);
            RolePlayer.instance.addEventListener(PlayerEvent.WALK_END, this.onWalkEndHandler);
            Dispatcher.dispatchEvent(new DataEvent(EventName.MapUpdateRolePosition, RolePlayer.instance.currentPoint));
            this._scene.addEventListener(flash.events.MouseEvent.MOUSE_DOWN, this.onSceneClickHandler);
            if (this._mouseFollow) 
            {
                this._mouseFollow.resetTarget(this._scene, 1500, this.startFollow);
            }
            else 
            {
                this._mouseFollow = new MouseFollow(this._scene, 1500, this.startFollow);
            }
            this._mouseFollow.setIntervalAction(1, this.addFollowObject);
            this._mouseFollow.setIntervalAction(5, this.followMoveTo);
            if (Cache.instance.role.entityInfo.life <= 0) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.Role_Dead));
            }
            MapDataUpdater.updateMapDataBySharp();
            ThingUtil.isEntitySort = true;
            ThingUtil.isMoveChange = true;
            this._scene.playerLayer.sortEntitys();
            this.onUpdateNPCStatus(cache.scene.allNpcStatusUpdate());
            AIManager.cancelAll();
            cache.scene.sceneChange();
            Dispatcher.dispatchEvent(new DataEvent(EventName.Scene_Update, Game.sceneInfo));
            if (this._tempMapPassTo) 
            {
                loc1 = this._tempMapPassTo;
                this._tempMapPassTo = null;
                this.mapPassTo(loc1);
            }
            if (cache.marry.marryCeremony) 
            {
                NetDispatcher.dispatchCmd(ServerCommand.MarryCeremonyCommand, cache.marry.marryCeremony);
                cache.marry.marryCeremony = null;
            }
            return;
        }

        /* internal  */startFollow(): void
        {
            var loc1;
            with ({}) 
            {
            };
            
#error('pushwith') {}
            .flash.utils.setTimeout(
#error('pushwith') {}
            .removeMark = (): void
            {
                _scene.removePointMark();
                return;
            }, 20)
            return;
        }

        public stopFollow(): void
        {
            if (this._mouseFollow) 
            {
                this._mouseFollow.stopFollow();
            }
            return;
        }

        /* internal  */isCanMove(): Boolean
        {
            if (!RolePlayer.instance.isInLayer) 
            {
                return false;
            }
            if (RolePlayer.instance.isMarryAction) 
            {
                return false;
            }
            if (RolePlayer.instance.fireEndWalking) 
            {
                return false;
            }
            if (RolePlayer.instance.isTweening) 
            {
                return false;
            }
            if (RolePlayer.instance.entityInfo.isStall) 
            {
                return false;
            }
            if (RolePlayer.instance.isDoubleRest) 
            {
                return false;
            }
            if (Cache.instance.fish.isInFishing) 
            {
                return false;
            }
            if (Cache.instance.fish.isInRoastFish) 
            {
                return false;
            }
            if (cache.arena.isInWaitingTime) 
            {
                return false;
            }
            return true;
        }

        /* internal  */addFollowObject(): void
        {
            if (!this.isCanMove()) 
            {
                return;
            }
            var loc1=new Object /* flash.geom.Point */(Global.stage.mouseX, Global.stage.mouseY);
            loc1 = this._scene.globalToLocal(loc1);
            this._scene.addMoveMark(loc1.x, loc1.y);
            return;
        }

        /* internal  */followMoveTo(): void
        {
            var loc1;
            if (!this.isCanMove()) 
            {
                return;
            }
            if (AIManager.isStopWalk || !RolePlayer.instance.isCanControlWalk) 
            {
                return;
            }
            if (!ScreenOperation.sceneOpt()) 
            {
                return;
            }
            ScreenOperation.interruptToOPT((): void
            {
                followMoveToImpl();
                return;
            })
            return;
        }

        /* internal  */followMoveToImpl(): void
        {
            GameController.guide.breakAutoPath();
            AIManager.cancelAll();
            var loc1=new Object /* flash.geom.Point */(Global.stage.mouseX, Global.stage.mouseY);
            loc1 = this._scene.globalToLocal(loc1);
            var loc2=GameMapUtil.getTilePoint(loc1.x, loc1.y);
            if (this._prePoint && loc2.equals(this._prePoint)) 
            {
                return;
            }
            this._prePoint = loc2;
            this._scene.moveRole(loc2);
            return;
        }

        /* internal  */onGirdWalkStartHandler(arg1: PlayerEvent): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.MapUpdateRolePosition, RolePlayer.instance.currentPoint));
            if (RolePlayer.instance.isCanControlWalk && !RolePlayer.instance.isMatch && !RolePlayer.instance.isInVideo) 
            {
                GameProxy.sceneProxy.move(RolePlayer.instance.serverPoints);
            }
            return;
        }

        /* internal  */onWalkEndHandler(arg1: PlayerEvent): void
        {
            this._scene.removePointMark();
            Dispatcher.dispatchEvent(new DataEvent(EventName.RoleMoveEnd, RolePlayer.instance.currentPoint));
            Dispatcher.dispatchEvent(new DataEvent(EventName.MapUpdateRolePosition, RolePlayer.instance.currentPoint));
            return;
        }

        public get selectEntity(): IEntity
        {
            return ThingUtil.selectEntity;
        }

        public clearPrePoint(): void
        {
            this._prePoint = null;
            return;
        }

        /* internal  */onSceneClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=null;
            var loc2=null;
            var loc3=null;
            var loc4=null;
            if (cache.copy.isInDefendCopy()) 
            {
                loc2 = ThingUtil.dropItemUtil.onClickScene();
                if (loc2) 
                {
                    GameProxy.sceneProxy.pikeEntity(loc2.entityId);
                    return;
                }
            }
            if (cache.copy.isInEatBeansCopy()) 
            {
                if (cache.eatBeans.doingStatus == EatBeansDoingStatus.StandBy) 
                {
                    MsgManager.showRollTipsMsg(Language.getString(80390));
                    return;
                }
                if (cache.eatBeans.doingStatus == EatBeansDoingStatus.End) 
                {
                    MsgManager.showRollTipsMsg(Language.getString(80387));
                    return;
                }
                if (typeof loc1 === "userplayer") 
                {
                    return;
                }
            }
            loc1 = ThingUtil.onClickScene();
            if (cache.copy.isInCrossDefenceCopy()) 
            {
                if (cache.crossDefenceCopy.isBuilding) 
                {
                    return;
                }
                if (loc1 is MonsterPlayer && BossRule.isDefenceTower(MonsterPlayer(loc1).bossInfo.type)) 
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.CrossDefenceClickTower, loc1));
                    return;
                }
            }
            if (loc1 is MonsterPlayer && BossRule.isFeedBoss(MonsterPlayer(loc1).bossType)) 
            {
                (loc1 as MonsterPlayer).selected = true;
                Dispatcher.dispatchEvent(new DataEvent(EventName.SnowmanBossClick, loc1));
                return;
            }
            if (RolePlayer.instance.entityInfo.isStall) 
            {
                if ((loc3 = loc1 as UserPlayer) && loc3.entityInfo.isStall) 
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.StallOpenStall, loc3.entityInfo.entityInfo.entityId));
                }
                else 
                {
                    MsgManager.showRollTipsMsg(Language.getString(90138));
                }
                return;
            }
            if (!ScreenOperation.sceneOpt()) 
            {
                return;
            }
            if (typeof loc1 === "userplayer") 
            {
                if ((loc4 = loc1 as UserPlayer) && loc4.entityInfo.isStall) 
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.StallOpenStall, loc4.entityInfo.entityInfo.entityId));
                    return;
                }
            }
            else if (typeof loc1 === "npcplayer") 
            {
                SoundManager.instance.soundPlay(SoundTypeConst.ClickNPC);
            }
            this.sceneClickEntity(loc1, arg1);
            return;
        }

        /* internal  */sceneClickEntity(arg1: GameSprite, arg2: Object /* flash.events.MouseEvent */): void
        {
            var loc1=null;
            var loc2=null;
            if (arg1 && arg1 is RolePlayer == false) 
            {
                this._scene.removePointMark();
                if (typeof arg1 === "ientity") 
                {
                    loc1 = arg1 as IEntity;
                    if (!RolePlayer.instance.isCanControlWalk) 
                    {
                        loc1.selected = true;
                        return;
                    }
                    if (cache.copy.isInRaceCopy() && loc1 is UserPlayer) 
                    {
                        loc1.selected = true;
                    }
                    else if (ThingUtil.entityUtil.isAttackAble(loc1, false) && !SystemSetter.currentSetter.clickToFight) 
                    {
                        if (loc1.selected) 
                        {
                            AIManager.onAIControl(arg1, AIType.AI_Entity);
                        }
                        else 
                        {
                            loc1.selected = true;
                        }
                    }
                    else 
                    {
                        loc1.selected = true;
                        AIManager.onAIControl(arg1, AIType.AI_Entity);
                    }
                }
                else 
                {
                    if (!RolePlayer.instance.isCanControlWalk) 
                    {
                        return;
                    }
                    AIManager.onAIControl(arg1, AIType.AI_Scene);
                }
            }
            else 
            {
                loc2 = GameMapUtil.getTilePoint(arg2.localX, arg2.localY);
                if (AutoFightRule.isAutoFight() || cache.guide.doubleClick && cache.guide.isGuideWolking()) 
                {
                    if (!this._doubleClickFlag && (!this._prePoint || !loc2.equals(this._prePoint))) 
                    {
                        this._doubleClickFlag = true;
                        flash.utils.setTimeout(this.onDoubleClickTimeOut, 400);
                        return;
                    }
                }
                if (AIManager.isStopWalk || !RolePlayer.instance.isCanControlWalk) 
                {
                    return;
                }
                GameController.guide.breakAutoPath();
                this._scene.addPointMark(arg2.localX, arg2.localY);
                AIManager.cancelAll();
                if (this._prePoint && loc2.equals(this._prePoint)) 
                {
                    return;
                }
                this._prePoint = loc2;
                this._scene.moveRole(loc2);
            }
            return;
        }

        /* internal  */onDoubleClickTimeOut(): void
        {
            this._doubleClickFlag = false;
            return;
        }

        /* internal  */doCoolDown(arg1: SBeginFight): void
        {
            var loc3=null;
            var loc4=null;
            if (arg1 == null) 
            {
                return;
            }
            var loc1=ThingUtil.entityUtil.getEntity(arg1.fromEntity) as SpritePlayer;
            if (typeof !(loc1 === "roleplayer")) 
            {
                return;
            }
            var loc2=0;
            var loc5=0;
            var loc6=arg1.propertyUpdates;
            label159: for(loc4 of loc6) 
            {
                var loc7=loc4.attribute.value();
                switch (loc7) 
                {
                    case EEntityAttribute._EAttributeAttackSkill:
                    {
                        loc2 = loc4.value;
                        continue label159;
                    }
                }
            }
            if (loc2 > 0) 
            {
                if (!(loc3 = SkillConfig.instance.getInfoByName(loc2)) || loc3.skillId >= 1199900 && loc3.skillId <= 1199909) 
                {
                    return;
                }
                if (loc3.skillType != ESkillType._ESkillTypeNormal) 
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.Skill_CoolDown, loc2));
                }
            }
            return;
        }

        protected /* override */ initServer(): void
        {
            NetDispatcher.addCmdListener(ECmdBroadCast._ECmdBroadcastEntityInfo, this.onBroadCastHandler);
            NetDispatcher.addCmdListener(ECmdBroadCast._ECmdBroadcastEntityInfos, this.onBroadCastHandler);
            NetDispatcher.addCmdListener(ECmdBroadCast._ECmdBroadcastEntityMoveInfo, this.onBroadCastHandler);
            NetDispatcher.addCmdListener(ECmdBroadCast._ECmdBroadcastEntityLeftInfo, this.onBroadCastHandler);
            NetDispatcher.addCmdListener(ECmdBroadCast._ECmdBroadcastEntityLeftInfos, this.onBroadCastHandler);
            NetDispatcher.addCmdListener(ECmdBroadCast._ECmdBroadcastEntityAttributeUpdate, this.onBroadCastHandler);
            NetDispatcher.addCmdListener(ECmdBroadCast._ECmdBroadcastEntityAttributeUpdates, this.onBroadCastHandler);
            NetDispatcher.addCmdListener(ECmdBroadCast._ECmdBroadcastEntityDropItem, this.onBroadCastHandler);
            NetDispatcher.addCmdListener(ECmdBroadCast._ECmdBroadcastEntityFlashInfo, this.onBroadCastHandler);
            NetDispatcher.addCmdListener(ECmdBroadCast._ECmdBroadcastEntityOwner, this.onBroadCastHandler);
            NetDispatcher.addCmdListener(ECmdBroadCast._ECmdBroadcaseEntityInfoToMySelf, this.onBroadCastHandler);
            NetDispatcher.addCmdListener(EPublicCommand._ECmdPublicRoleMoveTo, this.roleMoveTo);
            NetDispatcher.addCmdListener(ServerCommand.RoleSingleAttributeChange, this.onRoleAttrChange);
            NetDispatcher.addCmdListener(ECmdBroadCast._ECmdBroadcastEntityToEntityUpdate, this.onEntityToEntityUpdateHandler);
            NetDispatcher.addCmdListener(ECmdBroadCast._ECmdBroadcastEntityDoFight, this.onBroadCastHandler);
            NetDispatcher.addCmdListener(ECmdBroadCast._ECmdBroadcastEntityDoFights, this.onBroadCastHandler);
            NetDispatcher.addCmdListener(ECmdBroadCast._ECmdBroadcastEntityBeginFight, this.onBroadCastHandler);
            NetDispatcher.addCmdListener(ECmdBroadCast._ECmdBroadcastEntityBeginCollect, this.onBroadCastHandler);
            NetDispatcher.addCmdListener(ECmdBroadCast._ECmdBroadcastEntityNpcShop, this.onNpcShopBroadCastHandler);
            NetDispatcher.addCmdListener(ECmdBroadCast._ECmdBroadcastEntityDropSimpleItem, this.onEntityDropSimpleItemHandler);
            Dispatcher.addEventListener(EventName.SysSettingSuccess, this.onSysSettingSuccessHandler);
            Dispatcher.addEventListener(EventName.AttackRoleStatusChange, this.onAttackRoleStatusChangeHandler);
            NetDispatcher.addCmdListener(ServerCommand.BufferUpdate, this.onBufferUpdate);
            NetDispatcher.addCmdListener(ServerCommand.NPCTalk, this.onNPCTalkHandler);
            NetDispatcher.addCmdListener(EventName.NPC_Task_StatusUpdata, this.onUpdateNPCStatus);
            NetDispatcher.addCmdListener(EPublicCommand._ECmdPublicPassPointInfo, this.onPassPointInfoHandler);
            NetDispatcher.addCmdListener(EPublicCommand._ECmdPublicArenaCrossStatues, this.onArenaCrossStatuesHandler);
            NetDispatcher.addCmdListener(EGateCommand._ECmdGateCrossFlowerToplistStatue, this.onGateCrossFlowerToplistStatueHandler);
            Dispatcher.addEventListener(EventName.SkillUseSkill, this.onSkillFireHandler);
            Dispatcher.addEventListener(EventName.ItemUseItem, this.onItemUseHandler);
            Dispatcher.addEventListener(EventName.MountItemUseItem, this.onMountItemUseHandler);
            Dispatcher.addEventListener(EventName.LGXBDicCountChange, this.LGXBDicCountChangeHandler);
            Dispatcher.addEventListener(ServerCommand.MapPointUpdate, this.onMapPointUpdate, false, 1000);
            RolePlayer.instance.addEventListener(RolePlayerEvent.ControlStateChange, this.onControlStateChange);
            ClockManager.instance.addEventListener(TimeEvent.ServerOpenDayChange, this.onServerOpenDayChangeHandler);
            Dispatcher.addEventListener(EventName.CopyMoveToPassPoint, this.onMoveToPassPoint);
            Dispatcher.addEventListener(EventName.EatParadeProcess, this.onEatParadeProcess);
            return;
        }

        /* internal  */doHurts(arg1: Array<any>): void
        {
            var loc4=null;
            var loc5=null;
            var loc6=null;
            var loc7=null;
            var loc1=0;
            var loc2=0;
            var loc3=0;
            var loc8=0;
            var loc9=arg1;
            for(loc7 of loc9) 
            {
                if ((loc4 = ThingUtil.entityUtil.getEntity(loc7.entity) as SpritePlayer) == null) 
                {
                    continue;
                }
                loc4.updateEntityAttribute(loc7.propertyUpdates, false);
                loc5 = loc7.propertyUpdates;
                var loc10=0;
                var loc11=loc5;
                for(loc6 of loc11) 
                {
                    if (loc6.attribute.value() == EEntityAttribute._EAttributeHurt) 
                    {
                        loc2 = loc6.value;
                        continue;
                    }
                    if (loc6.attribute.value() != EEntityAttribute._EAttributeWuxingValue) 
                    {
                        continue;
                    }
                    loc3 = loc6.value;
                }
                loc1 = loc2 + loc3;
                if (loc1 == 0) 
                {
                    continue;
                }
                loc4.hurt(loc1);
            }
            return;
        }

        /* internal  */onServerOpenDayChangeHandler(arg1: TimeEvent): void
        {
            var loc1=null;
            var loc2=null;
            var loc3=0;
            var loc4=0;
            var loc5=null;
            if (this._scene && this._scene.isInitialize) 
            {
                loc1 = ActiveShieldConfig.instance.getNpcListBeforeDate(ClockManager.instance.serverOpenDate);
                var loc6=0;
                var loc7=loc1;
                for(loc3 of loc7) 
                {
                    loc2 = SceneConfig.instance.getSceneInfoByNpcId(loc3);
                    if (!loc2) 
                    {
                        continue;
                    }
                    this._scene.updateNpcIsAddToStage(loc3, false, loc2.sMapDefine.mapId);
                }
                loc1 = ActiveShieldConfig.instance.getEffectListBeforeDate(ClockManager.instance.serverOpenDate);
                loc6 = 0;
                loc7 = loc1;
                for(loc4 of loc7) 
                {
                    loc2 = SceneConfig.instance.getSceneInfoByEffectId(loc4);
                    if (!loc2) 
                    {
                        continue;
                    }
                    this._scene.udpateEffectIsAddToStage(loc4, false, loc2.sMapDefine.mapId);
                }
                if ((loc5 = cache.scene.getNearlyNpcByCopyId(CopyCodeRule.Copy129)) == null) 
                {
                    return;
                }
                if (ClockManager.instance.serverOpenDateNum >= 3) 
                {
                    this._scene.updateNpcIsAddToStage(loc5.id, true, loc5.mapId);
                    GameProxy.taskProxy.canGetTaskRefresh();
                }
                else 
                {
                    this._scene.updateNpcIsAddToStage(loc5.id, false, loc5.mapId);
                }
                this._serverOpenDayChange = false;
            }
            else 
            {
                this._serverOpenDayChange = true;
            }
            return;
        }

        /* internal  */onMoveToPassPoint(arg1: DataEvent): void
        {
            var loc1=arg1.data as SPassPoint;
            GameProxy.copy.moveToPassPoint(loc1.passPointId);
            return;
        }

        /* internal  */onEatParadeProcess(arg1: DataEvent): void
        {
            var loc1=arg1.data as int;
            var loc2=[];
            if (loc1 != 1) 
            {
                if (loc1 == 0) 
                {
                    this.updateParadeState(EatParadeConfig.instance.getActiveNpcIds(), 2);
                    this.updateParadeState(EatParadeConfig.instance.getParadeNpcIds(), 0);
                }
            }
            else 
            {
                this.updateParadeState(EatParadeConfig.instance.getActiveNpcIds(), 1);
                this.updateParadeState(EatParadeConfig.instance.getParadeNpcIds(), 2);
            }
            return;
        }

        /* internal  */updateParadeState(arg1: Array<any>, arg2: int): void
        {
            var loc1=0;
            var loc2=null;
            if (arg1 == null) 
            {
                return;
            }
            var loc3=0;
            while (loc3 < arg1.length) 
            {
                loc1 = arg1[loc3];
                if (loc2 = ThingUtil.npcUtil.getNpc(loc1)) 
                {
                    loc2.updateParadeState(arg2);
                }
                ++loc3;
            }
            return;
        }

        /* internal  */onRoleAttrChange(arg1: Object): void
        {
            RolePlayer.instance.showAttributChange(arg1 as AttributeValue);
            return;
        }

        /* internal  */roleMoveTo(arg1: MessageBlock): void
        {
            var loc3=null;
            var loc5=null;
            var loc1=arg1.messageBase as SPoints;
            var loc2=[];
            var loc4=0;
            while (loc4 < loc1.points.length) 
            {
                loc3 = loc1.points[loc4];
                loc5 = new AStarPoint(loc3.x, loc3.y);
                loc2.push(loc5);
                ++loc4;
            }
            RolePlayer.instance.walking(loc2);
            return;
        }

        /* internal  */onControlStateChange(arg1: RolePlayerEvent): void
        {
            if (!RolePlayer.instance.isCanControlReleaseMagic) 
            {
                if (SkillProgress.instance.running && SkillProgress.instance.type == ProcessType.Skill) 
                {
                    SkillProgress.instance.dispose();
                }
            }
            return;
        }

        /* internal  */onMapPointUpdate(arg1: DataEvent): void
        {
            var loc1=arg1.data as SPassTo;
            if (this._scene == null || this._scene.isInitialize == false) 
            {
                if (loc1.mapId == MapFileUtil.mapID) 
                {
                    this._tempMapPassTo = loc1;
                    return;
                }
                MapLoader.instance.stop();
                this._entritysAry.length = 0;
            }
            this.mapPassTo(loc1);
            return;
        }

        /* internal  */mapPassTo(arg1: SPassTo): void
        {
            var loc1=null;
            RolePlayer.instance.entityInfo.setNotFighting();
            if (arg1.passToId == 10 || !(arg1.mapId == MapFileUtil.mapID) || !(arg1.proxyId == MapFileUtil.proxyID) || !(arg1.serverId == MapFileUtil.serverID)) 
            {
                if (ThingUtil.selectEntity != null) 
                {
                    ThingUtil.selectEntity.selected = false;
                }
                Dispatcher.dispatchEvent(new DataEvent(EventName.LeaveScene, MapFileUtil.mapID));
                this._scene.clearAll();
                if (Game.sceneInfo) 
                {
                    Game.sceneInfo.clearStatue();
                }
                RolePlayer.instance.stopMove();
                MapFileUtil.mapID = arg1.mapId;
                MapFileUtil.proxyID = arg1.proxyId;
                MapFileUtil.serverID = arg1.serverId;
                GameMapUtil.curMapState.initMapId(arg1.mapId, arg1.proxyId, arg1.serverId);
                Dispatcher.dispatchEvent(new DataEvent(EventName.ChangeScene));
                this._scene.setPlayerPoint(arg1.mapId, arg1.toPoint.x, arg1.toPoint.y);
            }
            else 
            {
                loc1 = GameMapUtil.getPixelPoint(arg1.toPoint.x, arg1.toPoint.y);
                if (SceneRange.display.contains(loc1.x, loc1.y) == false) 
                {
                    if (ThingUtil.selectEntity) 
                    {
                        ThingUtil.selectEntity.selected = false;
                    }
                    this._scene.mapLayer.clearMap(true);
                }
                RolePlayer.instance.setTitlePoint(arg1.toPoint.x, arg1.toPoint.y);
                RolePlayer.instance.stopMove();
                ThingUtil.isEntitySort = true;
                ThingUtil.isMoveChange = true;
                this._scene.playerLayer.sortEntitys();
                Dispatcher.dispatchEvent(new DataEvent(EventName.ChangePosition, RolePlayer.instance.currentPoint));
            }
            this._scene.removePointMark();
            return;
        }

        /* internal  */onEntityDropSimpleItemHandler(arg1: MessageBlock): void
        {
            var loc1=arg1.messageBase as SDropItem;
            if (this._scene && this._scene.isInitialize) 
            {
                ThingUtil.dropItemUtil.addSimpleDropItem(loc1);
            }
            else 
            {
                this._simpleDropItem.push(loc1);
            }
            return;
        }

        /* internal  */onSysSettingSuccessHandler(arg1: DataEvent): void
        {
            if (ThingUtil.entityUtil) 
            {
                ThingUtil.entityUtil.updateLifeShow();
                ThingUtil.entityUtil.updateUserNameShow();
                ThingUtil.entityUtil.updateUserTitleShow();
                ThingUtil.entityUtil.updateNearPlayerPetShow();
                ThingUtil.entityUtil.updateWXPlayerShow();
                ThingUtil.entityUtil.updateSurroundPlayerShow();
                ThingUtil.entityUtil.updateFabaoPlayerShow();
                ThingUtil.entityUtil.updateHideModel();
                ThingUtil.entityUtil.updateWaistBeltPlayerShow();
                ThingUtil.entityUtil.updateElfPlayerShow();
            }
            if (ThingUtil.npcUtil) 
            {
                ThingUtil.npcUtil.updateEntity();
            }
            return;
        }

        /* internal  */onAttackRoleStatusChangeHandler(arg1: DataEvent): void
        {
            ThingUtil.entityUtil.updateHideModel();
            return;
        }

        /* internal  */onBufferUpdate(arg1: Object): void
        {
            var loc2=0;
            MouseRuleManager.addRule(this._scene, MouseThreeClickRule, this.threeClickCall);
            RolePlayer.instance.updateState(cache.buff.tStateArray);
            var loc1=0;
            while (loc1 < cache.buff.sBufferMsg.buffers.length) 
            {
                loc2 = (cache.buff.sBufferMsg.buffers[loc1] as SBuffer).code;
                RolePlayer.instance.updateBuffer(loc2, cache.buff.updateType);
                ++loc1;
            }
            return;
        }

        /* internal  */threeClickCall(): void
        {
            GameProxy.sceneProxy.removeSelfBuffer();
            MouseRuleManager.removeRule(this._scene, MouseThreeClickRule);
            return;
        }

        /* internal  */onNPCTalkHandler(arg1: SNpcTalk): void
        {
            var loc2=null;
            var loc3=null;
            var loc1=ThingUtil.npcUtil.getNpc(arg1.npcId);
            if (loc1) 
            {
                loc2 = ItemConfig.instance.getInfoByCode(arg1.bubbleId);
                loc3 = "";
                if (loc2) 
                {
                    loc3 = loc2.modelId;
                }
                loc1.talk(arg1.text, loc3);
            }
            return;
        }

        /* internal  */onPassPointInfoHandler(arg1: MessageBlock): void
        {
            ThingUtil.passUtil.addMapPass(arg1.messageBase as SMapPassPointList);
            return;
        }

        /* internal  */onArenaCrossStatuesHandler(arg1: MessageBlock): void
        {
            SceneConfig.instance.setStatuesNpc(arg1.messageBase as SArenaCrossStatues);
            return;
        }

        /* internal  */onGateCrossFlowerToplistStatueHandler(arg1: MessageBlock): void
        {
            SceneConfig.instance.setCrossFlowerNpc(arg1.messageBase as SCrossFlowerToplistStatues);
            return;
        }

        /* internal  */onUpdateNPCStatus(arg1: Array<any>): void
        {
            var loc1=0;
            var loc3=null;
            var loc4=null;
            if (arg1 == null) 
            {
                return;
            }
            var loc2=arg1.length;
            while (loc1 < loc2) 
            {
                loc3 = arg1[loc1];
                if ((loc4 = ThingUtil.npcUtil.getNpc(loc3.tnpc.npcId)) != null) 
                {
                    loc4.updateStatus(loc3);
                }
                ++loc1;
            }
            return;
        }

        /* internal  */onSkillFireHandler(arg1: DataEvent): void
        {
            var loc1=arg1.data as SkillInfo;
            SkillsUtil.instance.fireSkill(loc1, ThingUtil.selectEntity);
            return;
        }

        /* internal  */onItemUseHandler(arg1: DataEvent): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.BackPack_Use, arg1.data as ItemData));
            return;
        }

        /* internal  */onMountItemUseHandler(arg1: DataEvent): void
        {
            var loc1=arg1.data as ItemData;
            MountUtil.instance.equipMount(loc1);
            return;
        }

        /* internal  */LGXBDicCountChangeHandler(arg1: DataEvent): void
        {
            this.onUpdateNPCStatus(cache.scene.allNpcStatusUpdate());
            return;
        }

        /* internal  */onEntityInfoUpdateHandler(arg1: PlayerEvent): void
        {
            NetDispatcher.dispatchCmd(ServerCommand.EntityInfo_Update, null);
            return;
        }

        /* internal  */onEntityToEntityUpdateHandler(arg1: MessageBlock): void
        {
            var loc1=arg1.messageBase as SEntityIdPair;
            var loc2=ThingUtil.entityUtil.getEntity(loc1.fromEntityId) as UserPlayer;
            var loc3=ThingUtil.entityUtil.getEntity(loc1.toEntityId) as UserPlayer;
            if (loc2 && loc3) 
            {
                loc2.entityInfo.entityInfo.toEntitys2 = [loc1.toEntityId];
                if (loc2.isDoubleRest) 
                {
                    loc2.doubleRest();
                }
            }
            return;
        }

        /* internal  */onNpcShopBroadCastHandler(arg1: MessageBlock): void
        {
            var loc2=null;
            var loc1=arg1.messageBase as SNpcShop;
            if (!cache.copy.isInWeddingCopy()) 
            {
                this.entityNpcShop(loc1);
            }
            if (cache.copy.isInWeddingCopy() && GameController.marry.isRequestWeddingShop) 
            {
                loc2 = new NpcShopInfo();
                loc2.npcShop = loc1;
                Dispatcher.dispatchEvent(new DataEvent(EventName.OpenNpcShopMall, loc2));
                GameController.marry.isRequestWeddingShop = false;
            }
            return;
        }

        /* internal  */onBroadCastHandler(arg1: MessageBlock): void
        {
            var loc1=null;
            var loc2=null;
            var loc3=null;
            var loc4=null;
            var loc5=null;
            var loc6=null;
            var loc7=null;
            var loc8=arg1.messageHead.command;
            switch (loc8) 
            {
                case ECmdBroadCast._ECmdBroadcastEntityInfo:
                {
                    this.addEntity(arg1.messageBase as SEntityInfo);
                    break;
                }
                case ECmdBroadCast._ECmdBroadcastEntityInfos:
                {
                    this.addEntitys(arg1.messageBase as SSeqEntityInfo);
                    break;
                }
                case ECmdBroadCast._ECmdBroadcastEntityMoveInfo:
                {
                    loc1 = arg1.messageBase as SEntityMoveInfo;
                    this.moveEntity(loc1, loc1.points);
                    break;
                }
                case ECmdBroadCast._ECmdBroadcastEntityDropItem:
                {
                    this.dropItem(arg1.messageBase as SPacket);
                    break;
                }
                case ECmdBroadCast._ECmdBroadcastEntityLeftInfo:
                {
                    this.removeEntity(arg1.messageBase as SEntityId);
                    break;
                }
                case ECmdBroadCast._ECmdBroadcastEntityLeftInfos:
                {
                    loc2 = arg1.messageBase as SSeqEntityIdInfo;
                    ThingUtil.entityUtil.removeEntitys(loc2.entityIds);
                    break;
                }
                case ECmdBroadCast._ECmdBroadcastEntityAttributeUpdate:
                {
                    this.updateAttributes(arg1.messageBase as SEntityUpdate);
                    break;
                }
                case ECmdBroadCast._ECmdBroadcastEntityBeginFight:
                {
                    if (this._scene) 
                    {
                        loc3 = arg1.messageBase as SBeginFight;
                        if (!FrameUtil.canOperate()) 
                        {
                            this.doCoolDown(loc3);
                            break;
                        }
                        if (loc3.msgEx != null) 
                        {
                            ThingUtil.petbeginFight(loc3);
                        }
                        else 
                        {
                            ThingUtil.fightUtil.beginFight(loc3);
                        }
                    }
                    break;
                }
                case EGateCommand._ECmdGateShortcut:
                {
                    if (this._scene) 
                    {
                        ThingUtil.shortCutUtil.beginUse(arg1.messageBase as SShortcut);
                    }
                    break;
                }
                case ECmdBroadCast._ECmdBroadcastEntityDoFight:
                {
                    if (this._scene) 
                    {
                        loc4 = arg1.messageBase as SDoFight;
                        if (!FrameUtil.canOperate()) 
                        {
                            this.doHurts([loc4]);
                            break;
                        }
                        if (loc4.msgEx != null) 
                        {
                            ThingUtil.petDoFight(loc4);
                        }
                        else 
                        {
                            ThingUtil.fightUtil.doFight(loc4);
                        }
                    }
                    break;
                }
                case ECmdBroadCast._ECmdBroadcastEntityDoFights:
                {
                    if (this._scene) 
                    {
                        loc5 = arg1.messageBase as SDoFights;
                        if (!FrameUtil.canOperate()) 
                        {
                            this.doHurts(loc5.doFights);
                            break;
                        }
                        ThingUtil.fightUtil.doFights(loc5);
                    }
                    break;
                }
                case ECmdBroadCast._ECmdBroadcastEntityOwner:
                {
                    loc6 = arg1.messageBase as SEntityIdPair;
                    ThingUtil.entityUtil.updateAttack(loc6);
                    break;
                }
                case ECmdBroadCast._ECmdBroadcastEntityBeginCollect:
                {
                    if (this._scene) 
                    {
                        ThingUtil.collectUtil.beginFight(arg1.messageBase as SBeginFight);
                    }
                    break;
                }
                case ECmdBroadCast._ECmdBroadcastEntityFlashInfo:
                {
                    loc7 = arg1.messageBase as SEntityMoveInfo;
                    ThingUtil.entityUtil.refreshPoint(loc7.entityId, loc7.points);
                    break;
                }
                case ECmdBroadCast._ECmdBroadcaseEntityInfoToMySelf:
                {
                    cache.role.entityInfo = arg1.messageBase as SEntityInfo;
                    if (Game.isSceneInit()) 
                    {
                        Game.scene.initPlayer();
                    }
                    break;
                }
            }
            return;
        }

        public addEntitys(arg1: SSeqEntityInfo): void
        {
            var loc2=null;
            var loc1=arg1.entityInfos;
            var loc3=0;
            while (loc3 < loc1.length) 
            {
                loc2 = loc1[loc3];
                loc2.msgEx = arg1.msgEx;
                ++loc3;
            }
            if (this._scene && this._scene.isInitialize) 
            {
                ThingUtil.entityUtil.addEntitys(loc1);
            }
            else 
            {
                this._entritysAry = this._entritysAry.concat(loc1);
            }
            return;
        }

        public addEntity(arg1: SEntityInfo): void
        {
            if (this._scene && this._scene.isInitialize) 
            {
                ThingUtil.entityUtil.addEntity(arg1);
            }
            else 
            {
                this._entritysAry.push(arg1);
            }
            return;
        }

        private /* var */_scene: GameScene;

        private /* var */_entritysAry: Array<any>;

        private /* var */_dropItemAry: Array<any>;

        private /* var */_simpleDropItem: Array<any>;

        private /* var */_npcShopAry: Array<any>;

        private /* var */_mouseFollow: MouseFollow;

        private /* var */_prePoint: Object /* flash.geom.Point */;

        private /* var */_doubleClickFlag: Boolean;

        private /* var */_serverOpenDayChange: Boolean=false;

        private /* var */_tempMapPassTo: SPassTo;
    }
